<template>
  <div class="shopList" style="margin:24px 24px 0 24px;">
    <div class="disFlex Flex-middle search shadow">
      <Form
        :model="formItem"
        :label-width="120"
        style="display:flex;flex-direction:row;align-items:center;flex-flow:wrap;height: 100px;"
        class="searchForm"
      >
        <FormItem label="姓名">
          <Input v-model="formItem.workerNickname" placeholder="请输入简历名称" style="width:150px"/>
        </FormItem>
        <FormItem label="手机号码">
          <Input v-model="formItem.workerPhone" placeholder="请输入简历手机号码" style="width:150px"/>
        </FormItem>
        <FormItem label="时间查询类型">
          <Select v-model="formItem.searchType" style="width:100px">
            <Option value="timeCreate">创建时间</Option>
            <Option value="timeUpdate">更新日期</Option>
          </Select>
        </FormItem>
        <FormItem label style="margin-left:-95px">
          <Row>
            <Col span="11">
              <DatePicker type="date" placeholder="请选择开始时间" v-model="formItem.searchDataBegin"></DatePicker>
            </Col>
            <Col span="2" style="text-align: center">-</Col>
            <Col span="11">
              <DatePicker type="date" placeholder="请选择结束时间" v-model="formItem.searchDataFinish"></DatePicker>
            </Col>
          </Row>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchData">搜索</Button>
        </FormItem>
      </Form>
    </div>
    <TableList
      :columns="columns"
      :data="data"
      :page="page"
      :total="pageTotal*pageNum"
      :pageNum="pageNum"
      newOne="新建简历"
      @newOneFn="newOne"
      @changePage="changePage"
    ></TableList>
    <Modal title="Title" v-model="modal10" width="800" class-name="vertical-center-modal">
      <div style="min-height:200px;">
        <Table
          :columns="detailCol"
          :data="detailData"
          style="max-height:400px;overflow-y:scroll;"
          class="detailTable"
        ></Table>
      </div>
    </Modal>
  </div>
</template>

<script>
import TableList from "@/components/consumer/tableList";
import { WorkerList } from "api/recuit/resume";

export default {
  name: "",
  data() {
    return {
      formItem: {
        workerPhone: "",
        workerNickname: "",
        searchType: "timeCreate",
        searchDataBegin: "",
        searchDataFinish: ""
      },
      gender: ["未知", "男", "女"],
      educationArr: [
        "学历不限",
        "小学",
        "初中",
        "中专",
        "高中",
        "大学专科",
        "大学本科",
        "硕士",
        "博士",
        "博士后",
        "其它"
      ],
      experienceArr: [
        "经验不限",
        "无经验",
        "1年",
        "2年",
        "3年",
        "4年",
        "5年",
        "6年",
        "7年",
        "8年",
        "9年",
        "10年"
      ],
      columns: [
        {
          title: "用户信息",
          key: "user",
          width: 300,
          render: (h, params) => {
            return h(
              "div",
              {
                style: {
                  display: "flex",
                  alignItems: "center"
                }
              },
              [
                h("img", {
                  attrs: {
                    src: params.row.worker_avatar
                  },
                  style: {
                    padding: "2px",
                    width: "80px",
                    height: "80px"
                  },
                  on: {
                    click: () => {
                      // this.show(params.index);
                    }
                  }
                }),
                h(
                  "span",
                  {
                    style: {
                      marginLeft: "15px"
                    }
                  },
                  params.row.worker_nickname
                )
              ]
            );
          }
        },
        {
          title: "基本信息",
          key: "message",
          width: 300,
          render: (h, params) => {
            return h(
              "span",
              {
                style: {
                  marginLeft: "15px"
                }
              },
              this.gender[params.row.worker_gender] +
                "/" +
                (this.jsGetAge(params.row.worker_birthday) == 0
                  ? "年龄未知/"
                  : this.jsGetAge(params.row.worker_birthday) + "岁/") +
                this.educationArr[params.row.worker_education] +
                "/" +
                this.experienceArr[params.row.worker_experience]
            );
          }
        },
        {
          title: "简历完整度",
          key: "complate",
          width: 150,
          render: (h, params) => {
            return h("span", params.row.complete ? params.row.complete : "未创建");
          }
        },
        {
          title: "投递次数（次）",
          key: "postApplyJob",
          width: 150
        },
        {
          title: "联系电话",
          key: "worker_phone",
          width: 150
        },
        {
          title: "时间",
          key: "time_create",
          width: 200
        },
        {
          title: "操作",
          key: "action",
          width: 300,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "middle"
                  },
                  style: {
                    margin: "0 2px"
                  },
                  on: {
                    click: () => {
                      // this.show(params.index);
                      this.$router.push({
                        name: "resumeEdit",
                        params: { worderId: params.row.worker_id }
                      });
                    }
                  }
                },
                "简历详情"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "middle"
                  },
                  style: {
                    margin: "0 2px"
                  },
                  on: {
                    click: () => {
                      // this.show(params.index);
                      this.$router.push({
                        name: "postList",
                        params: { userSaasId: params.row.user_saas_id }
                      });
                    }
                  }
                },
                "投递记录"
              )
            ]);
          }
        }
      ],
      data: [],
      detailCol: [
        {
          title: "操作时间",
          key: "time"
        },
        {
          title: "操作名称",
          key: "name"
        },
        {
          title: "本次充值",
          key: "nowCash"
        },
        {
          title: "累计充值",
          key: "allCash"
        }
      ],
      detailData: [],
      modal10: false,
      page: 0,
      pageNum: 5, //显示条数
      jobSum: 0, //职位总数
      auditStatus: 1, //查询状态
      pageTotal: 0 //页面总数
    };
  },
  components: {
    TableList
  },

  mounted() {
    this.getData();
  },

  methods: {
    newOne() {
      this.$router.push({ name: "resumeEdit" });
    },
    //切换页面
    changePage(data) {
      let { page } = data;
      this.page = --page;
      this.getData();
    },
    //条件查询
    searchData() {
      this.page = 0;
      this.getData();
    },
    //获取数据
    getData() {
      let page = this.page;
      let pageNum = this.pageNum;
      let formItem = this.formItem;
      let dataList = new Object();
      dataList.page = ++page;
      dataList.pageNum = pageNum;
      //获取查询条件
      for (let i in formItem) {
        dataList[i] = formItem[i];
      }
      //时间段转换成时间戳
      dataList.searchDataBegin = dataList.searchDataBegin.valueOf() / 1000;
      dataList.searchDataFinish = dataList.searchDataFinish.valueOf() / 1000;

      WorkerList(dataList).then(res => {
        let { jobApplyList, jobApplyCount, page } = res;
        this.data = jobApplyList;
        this.companySum = jobApplyCount;
        this.pageTotal = page.pageTotal;
        this.page = Number(page.page)
      });
    },
    jsGetAge(strBirthday) {
      let returnAge;
      // 根据生日计算年龄（"1995-09-25"）
      //以下五行是为了获取出生年月日，如果是从身份证上获取需要稍微改变一下
      let strBirthdayArr = strBirthday.split("-");
      let birthYear = strBirthdayArr[0];
      let birthMonth = strBirthdayArr[1];
      let birthDay = strBirthdayArr[2];

      let d = new Date();
      let nowYear = d.getFullYear();
      let nowMonth = d.getMonth() + 1;
      let nowDay = d.getDate();

      if (nowYear == birthYear) {
        returnAge = 0; //同年 则为0岁
      } else {
        let ageDiff = nowYear - birthYear; //年之差
        if (ageDiff > 0) {
          if (nowMonth == birthMonth) {
            let dayDiff = nowDay - birthDay; //日之差
            if (dayDiff < 0) {
              returnAge = ageDiff - 1;
            } else {
              returnAge = ageDiff;
            }
          } else {
            let monthDiff = nowMonth - birthMonth; //月之差
            if (monthDiff < 0) {
              returnAge = ageDiff - 1;
            } else {
              returnAge = ageDiff;
            }
          }
        } else {
          returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
        }
      }
      return returnAge; //返回周岁年龄
    }
  }
};
</script>

<style scoped lang="less">
/*表头标题*/
.table-header-title {
  height: 100%;
  padding: 0 18px;
  box-sizing: border-box;
}

/*表头提示图标*/
.table-header-icon {
  font-size: 20px;
  margin-left: 10px;
}

/*弹窗标题*/
.alert-title {
  margin-top: 10px;
}

/*搜索*/
.search {
  padding: 18px;
  box-sizing: border-box;
  background: #fff;
  margin-bottom: 24px;
}

/*搜索下拉*/
.search-select {
  min-width: 128px;
  width: 128px;
  margin-right: 15px;
}

/*搜索输入框*/
.search-input {
  margin-right: 15px;
  top: 0;
}

.search-button {
  /* width: 80px;
    min-width: 80px; */
  margin-left: 15px;
}
.timeSpan {
  margin: 0 15px;
}
.detailTable::-webkit-scrollbar {
  width: 15px;
}
.detailTable tr {
  width: 700px;
}
.searchForm {
  .ivu-form-item {
    margin-bottom: 0;
  }
}
</style>
